package com.kandinfo.base.security.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import com.kandinfo.base.security.domain.Permission;

public interface PermissionRepository extends JpaRepository<Permission, Long>,
JpaSpecificationExecutor<Permission>{
    Permission findById(Long id);
    Permission findBypermName(String name);
   
    //用户管理
    @Query(value = "select * from perm where perm_name like 'admin_user:%'", nativeQuery = true)
    List<Permission> findLikeUser();
    //角色管理
    @Query(value = "select * from perm where perm_name like 'admin_role:%'", nativeQuery = true)
    List<Permission> findLikeRole();
    //基础数据管理
    @Query(value = "select * from perm where perm_name like 'basedata:%'", nativeQuery = true)
    List<Permission> findLikeBaseData();
    //工作流
    @Query(value = "select * from perm where perm_name like 'workflow:%' order by `index` asc", nativeQuery = true)
    List<Permission> findLikeWorkFlow();
    //分发规则
    @Query(value = "select * from perm where perm_name like 'distributerule:%'", nativeQuery = true)
    List<Permission> findLikeDistributeRule();
    //数据统计
    @Query(value = "select * from perm where perm_name like 'datastatistic:%'", nativeQuery = true)
    List<Permission> findLikeDataStatistic();
    //倒库
    @Query(value = "select * from perm where perm_name like 'export:%'", nativeQuery = true)
    List<Permission> findLikeExport();
    //隔离
    @Query(value = "select * from perm where perm_name like 'insulate:%'", nativeQuery = true)
    List<Permission> findLikeInsulate();
    @Query(value = "select * from perm where parent_id is null order by `index` asc ", nativeQuery = true)
    List<Permission> findorignPermissions();
    @Query(value = "select * from perm where parent_id =?1 order by `index` asc", nativeQuery = true)
    List<Permission> findChildPermissions(Long pid);
    
}
